package com.karrim.server.io.file;

import com.karrim.server.io.def.LengthLocator;
import com.karrim.server.io.file.def.FileLoader;
import com.karrim.server.io.file.def.FileStream;
import java.io.IOException;

/**
 *
 * @author andrea.cantafio
 */
public abstract class AbstractFileLoader<ContentType> implements FileLoader<ContentType> {

    public ContentType load(FileStream connectable, final int length) {
        try {
            return tryLoadLocated(connectable, new LengthLocator() {
                @Override
                public Integer get() {
                    return length;
                }
            });
        } catch (IOException ioe) {
            return null;
        }
    }

    @Override
    public ContentType load(FileStream connectable) {
        try {
            return tryLoadLocated(connectable, null);
        } catch (IOException ioe) {
            return null;
        }
    }

    public ContentType load(FileStream connectable, LengthLocator locator) {
        try {
            return tryLoadLocated(connectable, locator);
        } catch (IOException ioe) {
            return null;
        }
    }
}
